/**
 * 
 */
package model.solver;

import java.io.BufferedWriter;
import java.io.IOException;

import controller.xml.XMLBaliseFormat;


/**
 * Just like a {@link ESolver} but for an imported solver that cann't have a {@link ESolver}.
 * 
 * @author GRONOWSKI Stephane svan001@aol.com
 * 
 *         igsat 2010
 * 
 */
public class ImportESolver {
	/** The default value that is associate to a UNSATISFIABLE result */
	public static final int			RETURN_UNSATISFIABLE	= -200;
	/** The default value that is associate to a SATISFIABLE result */
	public static final int			RETURN_SATISFIABLE		= -1000;

	private String					execution;
	private String					description;
	private String					xmlValue;
	private int						satReturnValue			= RETURN_SATISFIABLE;
	private int						unsatReturnValue		= RETURN_UNSATISFIABLE;
	private ImportSolverParameter	defaultParam;


	/**
	 * * Create an {@link ImportESolver}
	 * 
	 * @param exec
	 *            the execution file
	 * @param description
	 *            a description
	 * @param xmlValue
	 *            xml value of the solver, convention says its the same as the execution file name,
	 *            do something different at your own risk.
	 * @param defaultparam
	 *            the default parameters of the solvers
	 */
	public ImportESolver(String exec, String description, String xmlValue, ImportSolverParameter defaultparam) {
		execution = exec;
		this.description = description;
		this.xmlValue = xmlValue;
		defaultParam = defaultparam;
	}

	/**
	 * Export the data in XML
	 * 
	 * @param file
	 *            {@link BufferedWriter} to write
	 * @throws IOException
	 */
	public void exportXML(BufferedWriter file) throws IOException {

		// open
		// file.newLine();
		file.write("<" + XMLBaliseFormat.IMPORTESOLVER + ">");

		// description
		// file.newLine();
		file.write("<" + XMLBaliseFormat.IMPORTESOLVER_DESCRIPTION + ">");
		file.write(description);
		file.write("</" + XMLBaliseFormat.IMPORTESOLVER_DESCRIPTION + ">");

		// execution
		// file.newLine();
		file.write("<" + XMLBaliseFormat.IMPORTESOLVER_EXEC + ">");
		file.write(execution);
		file.write("</" + XMLBaliseFormat.IMPORTESOLVER_EXEC + ">");

		// xml
		// file.newLine();
		file.write("<" + XMLBaliseFormat.IMPORTESOLVER_XMLVALUE + ">");
		file.write(xmlValue);
		file.write("</" + XMLBaliseFormat.IMPORTESOLVER_XMLVALUE + ">");

		// param
		defaultParam.exportXML(file);

		// close
		// file.newLine();
		file.write("</" + XMLBaliseFormat.IMPORTESOLVER + ">");
	}

	/**
	 * Return the description of the solver.
	 * 
	 * @return the description of the solver.
	 */
	public String getDescription() {
		return description;
	}

	/**
	 * Return the xmlValue, value that is supposed to written in the xml exportation.
	 * 
	 * @return the xmlValue
	 */
	public String getXmlValue() {
		return xmlValue;
	}

	/**
	 * Return the return value for SAT.
	 * 
	 * @return the satReturnValue
	 */
	public int getSatReturnValue() {
		return satReturnValue;
	}

	/**
	 * Set the return value for SAT.
	 * 
	 * @param satReturnValue
	 *            the satReturnValue to set
	 */
	public void setSatReturnValue(int satReturnValue) {
		this.satReturnValue = satReturnValue;
	}

	/**
	 * Return the return value for UNSAT.
	 * 
	 * @return the unsatReturnValue
	 */
	public int getUnsatReturnValue() {
		return unsatReturnValue;
	}

	/**
	 * Set the return value for UNSAT.
	 * 
	 * @param unsatReturnValue
	 *            the unsatReturnValue to set
	 */
	public void setUnsatReturnValue(int unsatReturnValue) {
		this.unsatReturnValue = unsatReturnValue;
	}

	/**
	 * Return the execution file name.
	 * 
	 * @return the execution
	 */
	public String getExecution() {
		return execution;
	}

	/**
	 * Set the execution file name.
	 * 
	 * @param execution
	 *            the execution to set
	 */
	public void setExecution(String execution) {
		this.execution = execution;
	}

	/**
	 * Set the description.
	 * 
	 * @param description
	 *            the description to set
	 */
	public void setDescription(String description) {
		this.description = description;
	}

	/**
	 * Set xml value of the solver.
	 * 
	 * @param xmlValue
	 *            the xmlValue to set
	 */
	public void setXmlValue(String xmlValue) {
		this.xmlValue = xmlValue;
	}

	/**
	 * Return the default {@link ImportSolverParameter}.
	 * 
	 * @return the defaultParam
	 */
	public ImportSolverParameter getDefaultParam() {
		return defaultParam;
	}

	@Override
	public String toString() {
		return description;
	}
}
